
<h1><span class="yiyi-st" id="yiyi-12">numpy.promote_types</span></h1>
        <blockquote>
        <p>原文：<a href="https://docs.scipy.org/doc/numpy/reference/generated/numpy.promote_types.html">https://docs.scipy.org/doc/numpy/reference/generated/numpy.promote_types.html</a></p>
        <p>译者：<a href="https://github.com/wizardforcel">飞龙</a> <a href="http://usyiyi.cn/">UsyiyiCN</a></p>
        <p>校对：（虚位以待）</p>
        </blockquote>
    
<dl class="function">
<dt id="numpy.promote_types"><span class="yiyi-st" id="yiyi-13"> <code class="descclassname">numpy.</code><code class="descname">promote_types</code><span class="sig-paren">(</span><em>type1</em>, <em>type2</em><span class="sig-paren">)</span></span></dt>
<dd><p><span class="yiyi-st" id="yiyi-14">返回<code class="docutils literal"><span class="pre">type1</span></code>和<code class="docutils literal"><span class="pre">type2</span></code>可以安全转换的最小尺寸和最小标量类型的数据类型。</span><span class="yiyi-st" id="yiyi-15">返回的数据类型始终以本机字节顺序。</span></p>
<p><span class="yiyi-st" id="yiyi-16">此函数是对称和关联的。</span></p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name">
<col class="field-body">
<tbody valign="top">
<tr class="field-odd field"><th class="field-name"><span class="yiyi-st" id="yiyi-17">参数：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-18"><strong>type1</strong>：dtype或dtype说明符</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-19">第一种数据类型。</span></p>
</div></blockquote>
<p><span class="yiyi-st" id="yiyi-20"><strong>type2</strong>：dtype或dtype说明符</span></p>
<blockquote>
<div><p><span class="yiyi-st" id="yiyi-21">第二种数据类型。</span></p>
</div></blockquote>
</td>
</tr>
<tr class="field-even field"><th class="field-name"><span class="yiyi-st" id="yiyi-22">返回：</span></th><td class="field-body"><p class="first"><span class="yiyi-st" id="yiyi-23"><strong>out</strong>：dtype</span></p>
<blockquote class="last">
<div><p><span class="yiyi-st" id="yiyi-24">提升的数据类型。</span></p>
</div></blockquote>
</td>
</tr>
</tbody>
</table>
<div class="admonition seealso">
<p class="first admonition-title"><span class="yiyi-st" id="yiyi-25">也可以看看</span></p>
<p class="last"><span class="yiyi-st" id="yiyi-26"><a class="reference internal" href="numpy.result_type.html#numpy.result_type" title="numpy.result_type"><code class="xref py py-obj docutils literal"><span class="pre">result_type</span></code></a>，<a class="reference internal" href="numpy.dtype.html#numpy.dtype" title="numpy.dtype"><code class="xref py py-obj docutils literal"><span class="pre">dtype</span></code></a>，<a class="reference internal" href="numpy.can_cast.html#numpy.can_cast" title="numpy.can_cast"><code class="xref py py-obj docutils literal"><span class="pre">can_cast</span></code></a></span></p>
</div>
<p class="rubric"><span class="yiyi-st" id="yiyi-27">笔记</span></p>
<div class="versionadded">
<p><span class="yiyi-st" id="yiyi-28"><span class="versionmodified">版本1.6.0中的新功能。</span></span></p>
</div>
<p><span class="yiyi-st" id="yiyi-29">从NumPy 1.9开始，promote_types函数现在返回一个有效的字符串长度，当给定整数或float dtype作为一个参数和字符串dtype作为另一个参数。</span><span class="yiyi-st" id="yiyi-30">以前，它总是返回输入字符串dtype，即使它不够长，不能存储转换为字符串的最大整数/浮点值。</span></p>
<p class="rubric"><span class="yiyi-st" id="yiyi-31">例子</span></p>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">promote_types</span><span class="p">(</span><span class="s1">&apos;f4&apos;</span><span class="p">,</span> <span class="s1">&apos;f8&apos;</span><span class="p">)</span>
<span class="go">dtype(&apos;float64&apos;)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">promote_types</span><span class="p">(</span><span class="s1">&apos;i8&apos;</span><span class="p">,</span> <span class="s1">&apos;f4&apos;</span><span class="p">)</span>
<span class="go">dtype(&apos;float64&apos;)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">promote_types</span><span class="p">(</span><span class="s1">&apos;&gt;i8&apos;</span><span class="p">,</span> <span class="s1">&apos;&lt;c8&apos;</span><span class="p">)</span>
<span class="go">dtype(&apos;complex128&apos;)</span>
</pre></div>
</div>
<div class="highlight-default"><div class="highlight"><pre><span></span><span class="gp">&gt;&gt;&gt; </span><span class="n">np</span><span class="o">.</span><span class="n">promote_types</span><span class="p">(</span><span class="s1">&apos;i4&apos;</span><span class="p">,</span> <span class="s1">&apos;S8&apos;</span><span class="p">)</span>
<span class="go">dtype(&apos;S11&apos;)</span>
</pre></div>
</div>
</dd></dl>
